package structureDonnee;

import java.util.LinkedList;

import verificateur.EnsembleVariable;



public class Inequalite {
	Expression expr;
	boolean strict; //ture si ( > ou <), false si ( >= ou <=)
	
	public Inequalite(){expr = new Expression();strict = false;}
	public Inequalite(Expression ex){
		expr = new Expression(ex.listExpr);
		strict = false; // >= par defaut
	}
	public Inequalite(Inequalite ine){
		expr = new Expression(ine.expr);
		strict = ine.strict;
	}
	public Inequalite(Expression ex, boolean b){
		expr = new Expression(ex.listExpr);
		strict = b;
	}
	public Inequalite(String s, EnsembleVariable ev){
		String ms = s;
		int i=0;
		int carLu=s.charAt(i);
//		System.out.println(s);
		StringBuffer buffer = new StringBuffer();
		
		do{
			buffer.append((char)carLu);
			i++;
			carLu = s.charAt(i);
		}while("><=".indexOf(carLu)==-1);
		
		//distingur > ou >=
		i++;
		int sss = s.charAt(i);
		if("=".indexOf(sss)==0) strict = false;
		else strict = true;
		
		ms = buffer.toString();
//		System.out.println(ms);
		if(carLu=='>') expr = new Expression(ms,ev);
		
		if(carLu=='<'){
			Expression tmp = new Expression(ms,ev);
			for(int j =0;j<tmp.listExpr.size();j++)
				tmp.listExpr.set(j, (-1)*tmp.listExpr.get(j));
			expr = tmp;
		}
	}
	
	//
	public Inequalite not(){
//		Inequalite not = new Inequalite();
		LinkedList<Double> tmp = new LinkedList<Double>();
		for (int i = 0; i<expr.listExpr.size();i++){
			tmp.add(i, -expr.listExpr.get(i));
		}
		Inequalite not =  new Inequalite(new Expression(tmp));
		not.strict = !this.strict;
		return not;
	}
	public Expression getExpr(){return expr;}
	public void pulish(EnsembleVariable ev){
		System.out.print("INE:");
		expr.publish(ev);
		if(strict) System.out.print(">0,");
		else System.out.print(">=0,");
//		System.out.println();
	}
}
